package com.groupsix.service.impl;

import com.groupsix.entity.Dormitoryinfo;
import com.groupsix.mapper.DormitoryinfoMapper;
import com.groupsix.service.DormitoryinfoService;
import com.groupsix.utils.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 董盛昌
 * @Title: ${file_name}
 * @Package ${package_name}
 * @Description: 宿舍信息业务逻辑接口实现类
 * @date 2021/10/18 0:12
 */
@Service
public class DormitoryinfoServiceImpl implements DormitoryinfoService {


    @Autowired
    private DormitoryinfoMapper dormitoryinfoMapper;


    //分页查询
    @Override
    public PageInfo findPageInfo(String aName, Integer sDormitoryid, String dDormbuilding, Integer pageIndex, Integer pageSize) {
        PageInfo pi = new PageInfo();
        pi.setPageIndex(pageIndex);
        pi.setPageSize(pageSize);
        //获取总条数
        Integer totalCount = dormitoryinfoMapper.totalCount(aName,sDormitoryid,dDormbuilding);
        if (totalCount>0){
            pi.setTotalCount(totalCount);
            //每一页显示宿舍信息数
            //currentPage = (pageIndex-1)*pageSize  当前页码数减1*最大条数=开始行数
            List<Dormitoryinfo> dormitoryinfoList =	dormitoryinfoMapper.getDormitoryinfoList(aName,sDormitoryid,dDormbuilding,
                    (pi.getPageIndex()-1)*pi.getPageSize(),pi.getPageSize());
            pi.setList(dormitoryinfoList);
        }
        return pi;
    }

    @Override
    public List<Dormitoryinfo> getAll(){
        List<Dormitoryinfo> dormitoryList = dormitoryinfoMapper.getAll();
        return dormitoryList;
    }

    //添加宿舍信息
    @Override
    public int addDormitoryinfo(Dormitoryinfo dormitoryinfo) {
        return dormitoryinfoMapper.addDormitoryinfo(dormitoryinfo);
    }

    //通过id删除宿舍信息
    @Override
    public int deleteDormitoryinfo(Integer dId) {
        return dormitoryinfoMapper.deleteDormitoryinfo(dId);
    }

    //修改宿舍信息
    @Override
    public int updateDormitoryinfo(Dormitoryinfo dormitoryinfo) {
        return dormitoryinfoMapper.updateDormitoryinfo(dormitoryinfo);
    }

    @Override
    public Dormitoryinfo findDormitoryinfoById (Integer dId){
        Dormitoryinfo d = dormitoryinfoMapper.findDormitoryinfoById(dId);
        return  d;
    }
    //查询宿舍人员信息
    @Override
    public List<Dormitoryinfo> findDormitoryinfoStudent(Dormitoryinfo dormitoryinfo) {
        List<Dormitoryinfo> d = dormitoryinfoMapper.findDormitoryinfoStudent(dormitoryinfo);
        return d;
    }


}
